import React, { Component } from 'react';
import { hashHistory } from 'react-router';
import './bookDesc.less';

class BookDesc extends Component{
	
	//开始阅读
	gotoRead = (bookinfo) => {
		if(bookinfo && bookinfo._id && bookinfo._id != ""){
			hashHistory.push("/bookRead/"+bookinfo._id);
		}
	}

	render(){
		const { bookinfo } = this.props;
		
		let bookImage = "";
		if(bookinfo && bookinfo.cover){
			if(bookinfo.cover.indexOf("http://") != -1){
				var index = bookinfo.cover.lastIndexOf("http");
				bookImage = bookinfo.cover.substring(index, bookinfo.cover.length);
			}else if(bookinfo.cover.indexOf("assets") != -1){
				bookImage = bookinfo.cover;
			}else{
				bookImage = "http://statics.zhuishushenqi.com"+bookinfo.cover;
			}
		}

		return(
			<div>
				<div className="book_detail">
					<div className="book_detail_left">
						<img src={bookImage}/>
					</div>
					<div className="book_detail_right">
						<span>{bookinfo.title}</span>
						<span className="book_detail_author">{bookinfo.author}</span>
						<span className="book_detail_price"></span>
						<span className="book_detail_read" onClick={() => this.gotoRead(bookinfo)}>开始阅读</span>
					</div>
				</div>
				<div className="book_detail_desc">
					{bookinfo.longIntro}
				</div>
				{/*
					<div className="book_detail_direct">
						<span>目录</span>
						<span>{`>`}</span>
					</div>
				*/}
			</div>
		)
	}
}

export default BookDesc;